package Web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import EmpDao.Emp;
import EmpDao.EmpDao;

public class AddEmpServlet extends HttpServlet {

	public void service(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		
		//1、接收传入的数据
		req.setCharacterEncoding("utf-8");
		String name=req.getParameter("name");
		String salary=req.getParameter("salary");
		String age=req.getParameter("age");
		
		//2、构造员工对象，好便于保存
		Emp emp=new Emp();
		emp.setName(name);
		emp.setSalary(new Double(salary));
		emp.setAge(new Integer(age));
		//3、保存员工
		EmpDao dao=new EmpDao();
		dao.save(emp);
		//4、响应：输出提示信息	
		res.setContentType("text/html;charset=utf-8");
		PrintWriter w = res.getWriter();
		w.println("<h1>新增成功</h1>");
		w.close();
	}

}
